#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: fast_demo.py 
@version:
@time: 2023/02/18 
"""
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):
    name: str
    price: float
    is_offer: Union[bool, None] = None


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}


@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
    return {"item_name": item.name, "item_id": item_id}


@app.post("/items")
def update_item(item: Item):
    return item
# pip install fastapi
# pip install uvicorn[standard]

# uvicorn fast_demo:app --reload

# uvicorn main:app 命令含义如下:
#
#     main：main.py 文件（一个 Python "模块"）。
#     app：在 main.py 文件中通过 app = FastAPI() 创建的对象。
#     --reload：让服务器在更新代码后重新启动。仅在开发时使用该选项。

# http://127.0.0.1:8000/docs
# http://127.0.0.1:8000/redoc

# pip install gunicorn
#  windows can't use
# gunicorn fast_demo:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:80
# windows can use
# uvicorn fast_demo:app --host 0.0.0.0 --port 8080 --workers 4
